
clear
set more off


cap log close
log using $logdir/refund_share.log, replace

use $fromsasdir/result if ertc + ertc_amendment > 0, clear
drop if ertc > 900*10^6
gen refund = max(0, -balance_due)

gen ertc_refund = min(ertc,refund)
gen ertc_f7200 = max(0, min(ertc-ertc_refund,f7200))
gen ertc_dep = max(0, ertc - ertc_refund - ertc_f7200)


gen post = tp >= 202103
gcollapse (sum) ertc_amendment ertc_refund ertc_f7200 ertc_dep, by(post) fast

egen tot = rowtotal(ertc_*)
foreach k in amendment refund f7200 dep {
    qui gen `k' = ertc_`k'/tot
}

gen ctype = ""

replace ctype = "2020Q2-2020Q4" if post == 0
replace ctype = "2021Q1-2021Q4" if post == 1


graph bar dep f7200 refund amendment, over(ctype) stack scheme(s1color) ///
	legend(order(1 "Reduced deposits" 2 "Form 7200 advance" 3 "Form 941 refund" 4 "941-X")) ///
	bar(1, fcolor(gs13) lcolor(black)) ///
        bar(2, fcolor(gs9) lcolor(black)) ///
        bar(3, fcolor(gs5) lcolor(black)) ///
        bar(4, fcolor(gs0) lcolor(black))

qui save $outdir/refund_share, replace

cap log close


